package one.stand.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.aop.ApiController;
import one.stand.model.ResultModel;
import one.stand.request.*;
import one.stand.response.AssembleResponse;
import one.stand.response.CompanyResponse;
import one.stand.response.GoodsAssembleResponse;
import one.stand.response.IndustryResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.util.List;
import java.util.Map;

/**
 * @author: ZRH
 * @CreateDate: 2019/4/17 9:45
 */
@RestController
@RequestMapping("crmPc/assemble")
@Api(description = "PC-拼团管理",tags="PC-拼团管理")
public class AssembleController extends BaseController{

    @PostMapping("insertGoodsAssemble")
    @ApiOperation(value = "添加拼团配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "assembleType", value = "0:草稿箱 1:正式发布", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "updateType", value = "草稿箱修改状态", paramType = "Integer"),
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "startTimes", value = "开团时间", required = true, paramType = "String"),
            @ApiImplicitParam(name = "endTimes", value = "结束时间", required = true, paramType = "String"),
            @ApiImplicitParam(name = "peopleNum", value = "开团人数", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "openRegiment", value = "单账号最多可开团数", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "joinRegiment", value = "单账号最多可参团数", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "maxPurchase", value = "单账号最多可购买数", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "goodSpecRequestList", value = "商品规格拼团金额和拼团库存", required = true, paramType = "list"),
    })
    @ApiController(isLogin = true, company = true, card = true, paramClass = GoodsAssembleRequest.class)
    public ResultModel<Boolean> insertGoodsAssemble(@RequestAttribute GoodsAssembleRequest request){
        return crmFegin.insertGoodsAssemble(request);
    }

    @PostMapping("selectGoodsAssembleDraftsPage")
    @ApiOperation(value = "拼团商品列表")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "assembleType", value = "0:草稿箱 1:正式发布", required = true, paramType = "Integer"),
            @ApiImplicitParam(name = "requestType", value = "1:进行中 2：已结束 3：全部", required = true, paramType = "Integer"),
    })

    @ApiController(isLogin = true, company = true, card = true, paramClass = GoodsAssembleRequest.class)
    public ResultModel<List<GoodsAssembleResponse>> selectGoodsAssembleDraftsPage(@RequestAttribute GoodsAssembleRequest request){
        return crmFegin.selectGoodsAssembleDraftsPage(request);
    }

    @PostMapping("delGoodsAssembleInfo")
    @ApiOperation(value = "拼团数据删除")
    @ApiImplicitParam(name = "assembleId", value = "拼团id", required = true, paramType = "Integer")
    @ApiController(isLogin = true, company = true, card = true, paramClass = GoodsAssembleRequest.class)
    public ResultModel<Boolean> delGoodsAssembleInfo(@RequestAttribute GoodsAssembleRequest request){
        return crmFegin.delGoodsAssembleInfo(request);
    }

    @PostMapping("releaseGoodsAssemble")
    @ApiOperation(value = "发布拼团配置")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "goodsId", value = "商品id", required = true, paramType = "Integer")
    })
    @ApiController(isLogin = true, company = true, card = true, paramClass = GoodsAssembleRequest.class)
    public ResultModel<Boolean> releaseGoodsAssemble(@RequestAttribute GoodsAssembleRequest request){
        return crmFegin.releaseGoodsAssemble(request);
    }

    @PostMapping("selectGoodsAssemblePage")
    @ApiOperation(value = "拼团列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "goodsName", value = "商品名称", paramType = "Integer"),
            @ApiImplicitParam(name = "state", value = "1拼团中，2拼团成功，3拼团失败，4已退款", paramType = "Integer"),
    })
    @ApiController(isLogin = true, company = true, card = true, paramClass = AssembleRequest.class)
    public ResultModel<List<AssembleResponse>> selectGoodsAssemblePage(@RequestAttribute AssembleRequest request){
        return crmFegin.selectGoodsAssemblePage(request);
    }

    @PostMapping("getGoodsAssembleInfo")
    @ApiOperation(value = "拼团详情")
    @ApiImplicitParam(name = "assembleId", value = "拼团id", required = true, paramType = "Integer")
    @ApiController(isLogin = true, company = true, card = true, paramClass = AssembleRequest.class)
    public ResultModel<AssembleResponse> getGoodsAssembleInfo(@RequestAttribute AssembleRequest request){
        return crmFegin.getGoodsAssembleInfo(request);
    }

    @PostMapping("updateGoodsAssembleInfo")
    @ApiOperation(value = "拼团列表编辑")
    @ApiImplicitParam(name = "assembleId", value = "拼团id", required = true, paramType = "Integer")
    @ApiController(isLogin = true, company = true, card = true, paramClass = AssembleRequest.class)
    public ResultModel<GoodsAssembleResponse> updateGoodsAssembleInfo(@RequestAttribute AssembleRequest request){
        return crmFegin.updateGoodsAssembleInfo(request);
    }
}
